package com.module.controller;

import com.module.framework.domain.Category;
import com.module.framework.domain.ResponseResult;
import com.module.framework.service.CategoryService;
import com.module.framework.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author JiHuiQin
 * @Date 2022/2/21 22:17
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;

	@GetMapping("/list")
	public ResponseResult categoryList(Integer pageNum, Integer pageSize, String name) {
		PageVO pageVO = categoryService.getCategoryList(pageNum, pageSize, name);
		return ResponseResult.okResult(pageVO);
	}

	@PostMapping("/add")
	public ResponseResult addCategory(@RequestBody Category category) {
		categoryService.addCategory(category);
		return ResponseResult.okResult();
	}

	@PostMapping("/update")
	public ResponseResult updateCategory(@RequestBody Category category) {
		categoryService.updateCategory(category);
		return ResponseResult.okResult();
	}

	@GetMapping("/delete")
	public ResponseResult deleteCategory(Integer id) {
		categoryService.deleteCategory(id);
		return ResponseResult.okResult();
	}
}
